<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>project-detail</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
  <link rel="stylesheet" href="../css/public.css" media="all">
  <style>
    .layui-form-label {
      width: 135px !important;
      text-align: center !important;
    }
    .layui-input-block{
      width: 400px !important;
      margin-left: 168px;
      min-height: 36px;
    }
  </style>
</head>

<body>
  <div class="layuimini-container">
    <div class="layuimini-main">
      <form class="layui-form" action="" lay-filter="company-detail">
        <div class="layui-row">
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">项目类型：</label>
              <div class="layui-input-block">
                <input type="text"  name="types_Pro" required  lay-verify="required" autocomplete="off" placeholder="请输入项目类型" class="layui-input">
              </div>
            </div>
          </div>
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">联系人：</label>
              <div class="layui-input-block">
                <input type="text"  name="concacts" required  lay-verify="required" autocomplete="off" placeholder="请输入联系人" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">项目编号：</label>
              <div class="layui-input-block">
                <input type="text"  name="pro_num" required  lay-verify="required" autocomplete="off" placeholder="请输入项目编号" class="layui-input">
              </div>
            </div>
          </div>
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">电话号：</label>
              <div class="layui-input-block">
                <input type="text"  name="phone" required  lay-verify="required" autocomplete="off" placeholder="请输入电话号" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">企业（单位）名称：</label>
              <div class="layui-input-block">
                <input type="text"  name="enterprise_name" required  lay-verify="required" autocomplete="off" placeholder="请输入企业（单位）名称" class="layui-input">
              </div>
            </div>
          </div>
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">录入时间：</label>
              <div class="layui-input-block">
                <input type="text"  name="create_time" id="create_time" required  lay-verify="required" placeholder="请选择日期" autocomplete="off" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">所属区县：</label>
              <div class="layui-input-block">
                <input type="text"  name="area" required  lay-verify="required" autocomplete="off" placeholder="请输入所属区县" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">项目名称：</label>
              <div class="layui-input-block">
                <input type="text"  name="pro_name" required  lay-verify="required" autocomplete="off" placeholder="请输入项目名称" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">项目类别：</label>
              <div class="layui-input-block">
                <input type="text"  name="pro_type"  autocomplete="off" required  lay-verify="required" placeholder="请输入项目类别" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">备案部门：</label>
              <div class="layui-input-block">
                <input type="text"  name="filing_dept" required  lay-verify="required" placeholder="请输入备案部门"  class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label">2020年实际投资额：</label>
              <div class="layui-input-block">
                <input type="text"  name="contract_amount" required  lay-verify="required"  placeholder="2020年实际投资额" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-col-md6">
            <div class="layui-form-item">
              <label class="layui-form-label required">计划完成时间：</label>
              <div class="layui-input-block">
                <input type="text" id="planned_completion_time" name="planned_completion_time" required  lay-verify="required" value=""  placeholder="请选择计划完成时间"autocomplete="off" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" id="goBackBtn">返回</button>
            <button class="layui-btn layui-btn-normal"  lay-submit style="display: none"; type="submit" lay-filter="subminBtn" id="subminBtn">添加</button>
            <button class="layui-btn layui-btn-normal"  lay-submit style="display: none"; type="submit" lay-filter="updateBtn" id="updateBtn">修改</button>
          </div>
        </div>
      </form>
    </div>
  </div>

  <script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
  <script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
  <script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
  <script src="../js/util.js"></script>

  <script>
    layui.use(['form', 'layer', 'laydate', 'miniTab'], function() {
      var form = layui.form,
        // laydate = layui.laydate,
        layer = layui.layer,
        miniTab = layui.miniTab,
        $ = layui.jquery,
              laydate = layui.laydate


//日期
      laydate.render({
        elem: '#planned_completion_time' //指定元素
      });
      laydate.render({
        elem: '#create_time' //指定元素
      });
      var _uuid;
//判断显示查看或者编辑或者修改
      let url = 'pro/queryJmDeclareByTaskID'
      let param = {
        taskID: getQueryVariable('id') // 获取url参数
      }
//新增
      if (getQueryVariable('type') === '2') {
        url = 'pro/queryJmDeclareByProcessInstanceID'
        param = {
          processInstanceID: getQueryVariable('id')
        }
		$("#subminBtn").show();
        //修改
      }else if(getQueryVariable('type') === '3'){
	  url = 'pro/queryJmDeclareByProcessInstanceID'
        param = {
          processInstanceID: getQueryVariable('id')
        }
	 $("#updateBtn").show();
        $.ajax({
          url: publicurl + 'pro/getProById',
          type: 'GET',
          data: {
            id: getQueryVariable('id') // 获取url参数
          },
          dataType: 'text',
          success: function(result) {
            //表单初始赋值
            result = JSON.parse(result)

            _uuid=result.obj.id
            form.val('company-detail', {
              "pro_type": result.obj.proType,
              "concacts": result.obj.concacts,
              "pro_num": result.obj.proNum,
              "phone": result.obj.phone,
              "enterprise_name": result.obj.enterpriseName,
              "create_time": result.obj.createTime,
              "area": result.obj.area,
              "pro_name": result.obj.proName,
              "types_Pro": result.obj.typesPro,
              "filing_dept": result.obj.filingDept,
              "contract_amount": result.obj.contractAmount,
              "planned_completion_time": result.obj.plannedCompletionTime,
            })
          },
          error: function(err) {
            console.log(err)
          }
        });
        //查看
	  }else if(getQueryVariable('type') === '4'){
        $("#create_time").attr("disabled", "disabled");
        $("#planned_completion_time").attr("disabled", "disabled");
        $('input:text').attr("readonly","readonly");
        $("#updateBtn").hide();
        $("#subminBtn").hide();

            $.ajax({
          url: publicurl + 'pro/getProById',
          type: 'GET',
          data: {
            id: getQueryVariable('id') // 获取url参数
          },
          dataType: 'text',
          success: function(result) {
            //表单初始赋值
            result = JSON.parse(result)
            console.log(result.obj)
            form.val('company-detail', {
              "pro_type": result.obj.proType,
              "concacts": result.obj.concacts,
              "pro_num": result.obj.proNum,
              "phone": result.obj.phone,
              "enterprise_name": result.obj.enterpriseName,
              "create_time": result.obj.createTime,
              "area": result.obj.area,
              "pro_name": result.obj.proName,
              "types_Pro": result.obj.typesPro,
              "filing_dept": result.obj.filingDept,
              "contract_amount": result.obj.contractAmount,
              "planned_completion_time": result.obj.plannedCompletionTime,
            })
          },
          error: function(err) {
            console.log(err)
          }
        });
      }

	  else{
        miniTab.openNewTabByIframe({
          href:"page/company.html",
          title:"项目库",
        });
	  }


      //监听返回
      $(document).on('click',"#goBackBtn",function(){
        var ele = $(".layuimini-tab .layui-tab-title li.layui-this", parent.document);
        if (ele.length > 0) {
          var layId = $(ele[0]).attr('lay-id');
          miniTab.openNewTabByIframe({
            href: "page/company.html",
            title: "项目库",
          });
          miniTab.delete(layId, true);
        }
      });



      // 添加
      // form.on('submit(formDemo)', function(data){
      //   layer.msg(JSON.stringify(data.field));
      //   return false;
      // });
      form.on('submit(subminBtn)', function(data){
          localStorage.setItem("TBaoID", 1);
          $.ajax({
            type: "post",
            url: '' + publicurl + 'pro/addPro',
            async: false,
            data: JSON.stringify({
              proType:$( "input[name='pro_type']").val(),
              concacts:$( "input[name='concacts']").val(),
              proNum:$( "input[name='pro_num']").val(),
              phone:$( "input[name='phone']").val(),
              enterpriseName:$( "input[name='enterprise_name']").val(),
              createTime:$( "input[name='create_time']").val(),
              area:$( "input[name='area']").val(),
              proName:$( "input[name='pro_name']").val(),
              typesPro:$( "input[name='types_Pro']").val(),
              filingDept:$( "input[name='filing_dept']").val(),
              contractAmount:$( "input[name='contract_amount']").val(),
              plannedCompletionTime:$( "input[name='planned_completion_time']").val()
            }),
            headers: { 'Content-Type': 'application/json' },
            success: function(res) {
              layer.alert('添加成功');
              layer.msg('提示框',{icon:5,time:1000});
              layer.open({
                content: '上传成功',
                time: 1500
              });
              var ele = $(".layuimini-tab .layui-tab-title li.layui-this", parent.document);
              if (ele.length > 0) {
                var layId = $(ele[0]).attr('lay-id');

                miniTab.openNewTabByIframe({
                  href:"page/company.html",
                  title:"项目库",
                });
                miniTab.delete(layId, true);
              }else{
                console.log("提示否则")
              }
            },
            error: function(request) {
              layer.alert(request.responseJSON.obj, {
                icon: 2,
                title: "提示失败",
              });
            }
          });

        //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value};获取单个值data.field["title"]
        //return false;
      })

//修改
    form.on('submit(updateBtn)', function(data){
      localStorage.setItem("TBaoID", 1);
      $.ajax({
        type: "post",
        url: '' + publicurl + 'pro/addPro',
        async: false,
        data: JSON.stringify({
          id:_uuid,
          proType:$( "input[name='pro_type']").val(),
          concacts:$( "input[name='concacts']").val(),
          proNum:$( "input[name='pro_num']").val(),
          phone:$( "input[name='phone']").val(),
          enterpriseName:$( "input[name='enterprise_name']").val(),
          createTime:$( "input[name='create_time']").val(),
          area:$( "input[name='area']").val(),
          proName:$( "input[name='pro_name']").val(),
          typesPro:$( "input[name='types_Pro']").val(),
          filingDept:$( "input[name='filing_dept']").val(),
          contractAmount:$( "input[name='contract_amount']").val(),
          plannedCompletionTime:$( "input[name='planned_completion_time']").val()
        }),
        headers: { 'Content-Type': 'application/json' },
        success: function(res) {
          layer.alert('修改');
          layer.msg('提示框',{icon:5,time:1000});
          layer.open({
            content: '上传成功',
            time: 1500
          });
          var ele = $(".layuimini-tab .layui-tab-title li.layui-this", parent.document);
          if (ele.length > 0) {
            var layId = $(ele[0]).attr('lay-id');
            miniTab.openNewTabByIframe({
              href:"page/company.html",
              title:"项目库",
            });
            miniTab.delete(layId, true);
          }else{
            console.log("提示否则")
          }
        },
        error: function(request) {
          layer.alert(request.responseJSON.obj, {
            icon: 2,
            title: "提示失败",
          });
        }
      });

    //  console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value};获取单个值data.field["title"]

      //return false;
    })
    });
    // function getQueryVariable(variable) {
    //   var query = window.location.search.substring(1);
    //   var vars = query.split("&");
    //   for (var i = 0; i < vars.length; i++) {
    //     var pair = vars[i].split("=");
    //     if (pair[0] == variable) { return pair[1]; }
    //   }
    //   return (false);
    // }

/*
    $.ajax({
      url: publicurl + 'pro/getProById',
      type: 'GET',
      data: {
        id: getQueryVariable('id') // 获取url参数
      },
      dataType: 'text',
      success: function(result) {
        //++++
        var jsons=JSON;
        console.log(jsons)
        //---
        console.log(getQueryVariable)
        //表单初始赋值
        result = JSON.parse(result)
        form.val('company-detail', {
          "pro_type": result.obj.proType,
          "concacts": result.obj.concacts,
          "pro_num": result.obj.proNum,
          "phone": result.obj.phone,
          "enterprise_name": result.obj.enterpriseName,
          "create_time": result.obj.createTime,
          "area": result.obj.area,
          "pro_name": result.obj.proName,
          "pro_type": result.obj.proType,
          "filing_dept": result.obj.filingDept,
          "contract_amount": result.obj.contractAmount,
          "planned_completion_time": result.obj.plannedCompletionTime,
        })
      },
      error: function(err) {
        console.log(err)
      }
    });
    */
  </script>

</body>

</html>